<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet" type="text/css" media="screen" href="css/redmond/jquery-ui-1.10.3.custom.min.css" />	<!-- jqueryUI CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />							<!-- jqGrid CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/selfTemplate.css" />						<!-- 本專案自行定義 CSS -->

<script src="js/jquery-1.10.2.min.js"></script>		<!-- jQuery 核心 -->
<script src="js/grid.locale-tw.js" type="text/javascript"></script>											<!-- jqGrid 語系檔 -->
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>										<!-- jqGrid 核心 -->
<script src="js/jquery-ui-1.10.3.custom.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->
<script src="js/jquery.cookie.js"></script>																	<!-- 操作cookie用 -->
<script src="js/widgets.js" type="text/javascript"></script>												<!-- 本專案自行定義 JS -->

<title>維護人員</title>

<script type="text/javascript">



$(document).ready(function() {
	init("roleAssign.html");
	
	var t = querySubsys( $.cookie("empId"),$.cookie("pageName"),"subsysId");

	if( t==1 ) {
		windowFreeze("畫面初始中");
		
		$.post("QueryRoleList", { isSU: $.cookie("isSU") }, function(reses) {
			$("select#role option").remove();
			
			$("select#role").append("<option value='noselect'  id='dOpt'>--請選擇--</option>");
			
			if ( $(reses).size() >0 ) {
				$.each(reses,function(i, res) {
					tmp = "<option value='"+res.id+"'>"+res.name+"</option>";
					$("select#role").append(tmp);
				});
			}
		});
		
		$("select#subsysId").bind("change", function(){
			$("select#subsysId #dOpt").remove();
			chgPeoList();
		});

		$("select#role").bind("change", function(){
			$("select#role #dOpt").remove();
			chgPeoList();
		});
		//項目被點選，會影響按鈕能否被按下
		$("select#notInPeople").change(function(){
			chkButtonClickAble();
		});
		//項目被點選，會影響按鈕能否被按下
		$("select#inPeople").change(function(){
			chkButtonClickAble();
		});
		
		
		$(".dialog").css("visibility","hidden");
		
		$("button.remove").bind("click", function() {
			/*
			1. 將選的加入 delList
			2. 加入 notInList
			3. 移出 inList
			*/
			var tmp = "";
			var subsysId = $("select#subsysId  option:selected").val();	//子系統
			var roleId = $("select#role  option:selected").val();		//角色
			var creatorId = $.cookie("empId");
			
			$("select#inPeople option"+$(this).val() ).each( function(){
				$.ajax({type:"post",url:"UpdateEmpRole",dataType: "json",
					data : {subsysId:subsysId,roleId:roleId,creatorId:creatorId,addOrDelete:"delete",empId:$(this).val()},
					success : function(reses) { if (reses != "") { $("#errShortMsg").html(reses); } }
				});
				$("select#notInPeople").append("<option value='"+$(this).val()+"'>"+$(this).html()+"</option>");
				$(this).remove();
			});	
			chkButtonClickAble();
		});
		
		$("button.add").bind("click", function() {
			/*
			1. 將選的加入 addList
			2. 加入 inList
			3. 移出 notInList
			*/
			var tmp = "";
			var subsysId = $("select#subsysId  option:selected").val();	//子系統
			var roleId = $("select#role  option:selected").val();		//角色
			var creatorId = $.cookie("empId");
			
			$("#notInPeople option"+$(this).val() ).each( function(){
				$.ajax({type:"post",url:"UpdateEmpRole",dataType: "json",
					data : {subsysId:subsysId,roleId:roleId,creatorId:creatorId,addOrDelete:"add",empId:$(this).val()},
					success : function(reses) { if (reses != "") { $("#errShortMsg").html(reses); } }
				});
				$("select#inPeople").append("<option value='"+$(this).val()+"'>"+$(this).html()+"</option>");
				$(this).remove();
			});	
			chkButtonClickAble();
		});
		
		chkButtonClickAble();
		windowUnfreeze();
	}
	
	$("#isQueryCheck").button({icons:{ primary: "ui-icon-check" }});
	
}).tooltip();
</script>

</head>
<body>

<div id="header"></div>
<p>

<table id="parTable" >
	<thead class="tableFirst">
		<tr>
			<th class="right"><label for="subsysId">子系統：</label></th>
			<td class="left" colspan="2"><select class="zhTwN" id="subsysId"><option value='noselect' id='dOpt'>--請選擇--</option></select></td>
		</tr>
		<tr>
			<th class="right"><label for="role">角色：</label></th>
			<td class="left"><select class="zhTwN" id="role"><option value='noselect' id='dOpt'>--請選擇--</option></select></td>
		</tr>
		<tr><td colspan="3">&nbsp;</td> </tr>
		<tr>
			<td rowspan="4">其它人員：<br><select class="zhTwN" id="notInPeople" multiple="multiple" size="5" ></select></td> 
			<td><button id="btnAddAll" value="" class="zhTwN add" type="button">全部加入</button></td>
			<td  rowspan="4">選取人員：<br><select class="zhTwN" id="inPeople" multiple="multiple" size="5" ></select></td>	
		</tr>
		<tr>
			<td><button id="btnAddSel" class="zhTwN add" value=":selected" type="button">選取加入</button></td>
		</tr>
		<tr>
			 <td><button id="btnRemoveSel" class="zhTwN remove" value=":selected" type="button">選取移除</button></td>
		</tr>
		<tr>
			<td><button id="btnRemoveAll" value="" class="zhTwN remove" type="button">全部移除</button></td>
		</tr>
	</thead>
</table>
</body>
</html>